package com.qpl.depression.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qpl.depression.entity.Article;
import com.qpl.depression.entity.Category;
import com.qpl.depression.service.ArticleService;
import com.qpl.depression.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * @Desc
 * @Date 2021/5/13 11:09
 **/
@Controller
public class CategoryController {

    @Autowired
    private CategoryService categoryService;
    @Autowired
    private ArticleService articleService;

    /**
     * 跳转到试题分类页面
     *
     * @param modelMap 存放数据
     * @return 试题页面
     */
    @GetMapping("category/page")
    public String categoryPage(ModelMap modelMap) {
        List<Category> categories = categoryService.list(Wrappers.<Category>lambdaQuery().eq(Category::getStatus, 1));
        modelMap.addAttribute("categories", categories);
        List<Article> articles = articleService.getByRandom();
        modelMap.addAttribute("articles", articles);
        return "category";
    }


}
